package operation;

import book.BookList;
import book.Book;

import java.util.Scanner;

public class DelOperation implements IOperation{
    public void work(BookList bookList){
        System.out.println("删除图书！");
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入删除图书的名字:");
        String name = scan.nextLine();

        int currentSize = bookList.getUsedSize();
        int index=-1;
        for(int i=0;i<currentSize;++i){
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)){
                index=i;
                break;
            }
        }
        if(index==-1){
            System.out.println("没有这本图书");
            return;
        }

        for(int i=index;i<currentSize-1;++i){
            Book book = bookList.getBook(i+1);
            bookList.setBookList(i,book);
        }
        bookList.setUsedSize(currentSize-1);

    }
}
